﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;

namespace Leo.Common.Logger
{
    /// <summary>
    /// 服务注册 扩展
    /// </summary>
    public static class ServiceCollectionExtensions
    {
        public static IServiceCollection AddLog(this IServiceCollection services, string? configPath = null)
        {
            NLogConfigurator.Init(configPath);
            return services
                .AddSingleton<ILogs, Logs>()
                .AddSingleton(typeof(ILogs<>), typeof(Logs<>))
                .AddLogging(logging =>
                {
                    logging.ClearProviders();
                    logging.AddNLog();
                });
        }
    }
}
